import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

Vue.prototype.toast = (msg) => {
	uni.showToast({
		title: msg,
		duration: 2000,
		position: 'bottom',
		icon: 'none',
		mask: true
	});
};
/**
 * 上传图片到阿里云OSS
 */
Vue.prototype.oss_upload = (res, name, data) => {
	var imageSrc = res.tempFilePaths[0];
	var arr = imageSrc.split(".");
	var timestamp = new Date().getTime();
	uni.uploadFile({
		url: 'https://ykp-new.oss-cn-hangzhou.aliyuncs.com/',
		filePath: imageSrc,
		fileType: 'image',
		name: 'file',
		formData: {
			name: res.tempFilePaths[0],
			key: name,
			policy: 'eyJleHBpcmF0aW9uIjoiMjAzMC0wMS0wMVQxMjowMDowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF1dfQ==',
			OSSAccessKeyId: 'LTAI4FcXYWmp9m5r5Sy1W6Aq',
			success_action_status: 200,
			signature: 'gHwVJrgX3eCYdTqd414wUdJEpGc='
		},
		success: (res) => {
			console.log(timestamp);
			data.success(res)
		},
		fail: (res) => {
			data.fail(res)
		},
	});
};
App.mpType = 'app'
Vue.prototype.ajax = (url, data) => {
	var temp_data = data.data;
	if (temp_data == undefined) temp_data = {};
	var urls = '/phone/' + url;
	var header = {
		'Content-Type': 'application/json'
	};
	uni.request({
		url: urls,
		data: temp_data,
		method: "POST",
		header: header,
		success: (res) => {
			res = res.data;
			data.success(res)
		},
		fail: () => {
			uni.stopPullDownRefresh();
			uni.showToast({
				title: '请求失败',
				duration: 2000,
				icon: 'none'
			});
		},
		complete: () => {}
	})
};
const app = new Vue({
    ...App
})
app.$mount()
